package com.androidcentralmedias;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
 
import android.util.Log;
 
public class Client {
        
        public static void enviar(String pacote) {
                try {
                		String pacoteResto;
                		int n=0;
                        // Retrieve the ServerName
                        InetAddress serverAddr = InetAddress.getByName("192.168.1.101");//ip 10.0.2.2 para emulador
                        /* Create new UDP-Socket */
                        DatagramSocket socket = new DatagramSocket();
                        /* Prepare some data to be sent. */
                        byte[] outData = (pacote).getBytes();
                       
                        /* Create UDP-packet with
                         * data & destination(url+port) */
                        DatagramPacket packet = new DatagramPacket(outData, outData.length,     serverAddr, 1235); //Client do Android e Server do PC na 1235
                        Log.d("UDP", "C: Sending: '" + new String(packet.getData(),0, packet.getLength()));
                        /* Send out the packet */
                        socket.send(packet);
                } catch (Exception e) {
                        Log.e("UDP", "C: Error", e);
                }
        }
}